part of '../repository.dart';

const _kLearningSettingsDataAutoPronunciationEnabledKey = 'auto_pronunciation_enabled';
const _kLearningSettingsDataTrainingSettingsDataKey = 'training_settings';

class _LearningSettingsDataDto extends Equatable {
  const _LearningSettingsDataDto._internal({
    required this.autoPronunciationEnabled,
    required this.trainingSettingsDataDto,
  });

  final bool autoPronunciationEnabled;
  final _TrainingSettingsDataDto trainingSettingsDataDto;

  @override
  List<Object?> get props {
    return [
      autoPronunciationEnabled,
      trainingSettingsDataDto,
    ];
  }

  factory _LearningSettingsDataDto.fromJson(Map<String, dynamic> json) {
    final trainingSettingsDataMap = json[_kLearningSettingsDataTrainingSettingsDataKey] as Map;

    final trainingSettingsDataJson =
        Map.castFrom<dynamic, dynamic, String, dynamic>(trainingSettingsDataMap);

    final trainingSettingsDataDto = _TrainingSettingsDataDto.fromJson(trainingSettingsDataJson);

    return _LearningSettingsDataDto._internal(
      autoPronunciationEnabled: json[_kLearningSettingsDataAutoPronunciationEnabledKey],
      trainingSettingsDataDto: trainingSettingsDataDto,
    );
  }

  factory _LearningSettingsDataDto.fromEntity(LearningSettingsData learningSettingsData) {
    final trainingSettingsDataDto =
        _TrainingSettingsDataDto.fromEntity(learningSettingsData.trainingSettingsData);

    return _LearningSettingsDataDto._internal(
      autoPronunciationEnabled: learningSettingsData.autoPronunciationEnabled,
      trainingSettingsDataDto: trainingSettingsDataDto,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kLearningSettingsDataAutoPronunciationEnabledKey: autoPronunciationEnabled,
      _kLearningSettingsDataTrainingSettingsDataKey: trainingSettingsDataDto.toJson(),
    };
  }

  LearningSettingsData toEntity() {
    return LearningSettingsData(
      autoPronunciationEnabled: autoPronunciationEnabled,
      trainingSettingsData: trainingSettingsDataDto.toEntity(),
    );
  }
}
